<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Materi extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('uwd');
        $this->load->helper('download');
        $this->load->library('parser');
    }

    function download() {
        $id = $this->uri->segment(3);
        $path = $this->uwd->get_link($id);
        $data = file_get_contents($path->full_path); // Read the file's contents
        $name = $path->file_name;
        $ht = $path->download;
        $tmbh = $ht + 1;
        $dat = array(
            'download' => $tmbh
        );
        $this->uwd->hitung($id, $dat);
        force_download($name, $data);
        redirect('admin/materi');
    }

    function matakuliah() {
        $data['title'] = 'Universitas Widya Dharma';
        $data['name'] = 'E-Learning';
        $d = $this->uri->segment(3);
        $id = str_replace('%20', ' ', $d);
        if ($this->uwd->by_matkul($id)) {
            $data['matkul'] = $this->uwd->by_matkul($id);
            $data['matakuliah'] = $id;
        } else {
            $data['matkul'] = array();
            $data['matakuliah'] = $id;
        }
        if ($this->uwd->materi_dosen($id)) {
            $data['dosen'] = $this->uwd->materi_dosen($id);
        } else {
            $data['dosen'] = array();
        }
        $this->parser->parse('default/head', $data);
        $this->parser->parse('default/listMateri', $data);
        $this->load->view('default/footer');
    }

    function detail() {
        $data['title'] = 'Universitas Widya Dharma';
        $data['name'] = 'E-Learning';
        $id = $this->uri->segment(3);
        $da = $this->uwd->detail_materi($id);
        $data['judul'] = $da->judul;
        $data['date'] = $da->date;
        $data['dosen'] = $da->nama;
        $data['matkul'] = $da->matkul;
        $data['sinopsis'] = $da->sinopsis;
        $data['download'] = $da->download;
        $data['status'] = $da->status;
        $data['hash'] = $da->hash;
        $dosen = $da->nama;
        if ($this->uwd->materi_lain($dosen)) {
            $data['materi'] = $this->uwd->materi_lain($dosen);
        } else {
            $data['materi'] = array();
        }
        $this->parser->parse('default/head', $data);
        $this->parser->parse('default/materi', $data);
        $this->load->view('default/footer');
    }

    function dosen() {
        $data['title'] = 'Universitas Widya Dharma';
        $data['name'] = 'E-Learning';
        $d = $this->uri->segment(3);
        $id = str_replace('%20', ' ', $d);
        if ($this->uwd->mat_dosen($id)) {
            $data['materi_dosen'] = $this->uwd->mat_dosen($id);
        } else {
            $data['materi_dosen'] = array();
        }
        if ($this->uwd->matkul_ampu($id)) {
            $data['materi_ampu'] = $this->uwd->matkul_ampu($id);
        } else {
            $data['materi_ampu'] = array();
        }
        $data['dosen'] = $id;
        $this->parser->parse('default/head', $data);
        $this->parser->parse('default/materi_dosen', $data);
        $this->load->view('default/footer');
    }

    function daftar_dosen() {
        $data['title'] = 'Universitas Widya Dharma';
        $data['name'] = 'E-Learning';
//        $d = $this->uri->segment(3);
//        $id = str_replace('%20', ' ', $d);
        if ($this->uwd->dftr_dosen()) {
            $data['dosen'] = $this->uwd->dftr_dosen();
        } else {
            $data['dosen'] = array();
        }
        $this->parser->parse('default/head', $data);
        $this->parser->parse('default/dftrDosen', $data);
        $this->load->view('default/footer');
    }

}

?>
